class ReviewController < ApplicationController
  layout "home" 
  
  def goreview
    session[:user_id]=2;#test
    current_user_id=session[:user_id]
    @user=User.find(current_user_id)
    respond_to do |format|
      format.html {render :template=> "/review/goreview"}
    end
  end
  def startreview
#    auto_complete_for :enterprise,:enterprise_name
    if params[:city][:enterprise_id].to_i<1
      flash[:notice]="Pls选择商家"
      respond_to do |format|
        format.html {render :template=> "/review/goreview"}
      end
    else
      session[:enterprise_id]=params[:city][:enterprise_id]
      respond_to do |format|
        format.html {render :template=> "/review/startreview"}
      end
    end
  end
  def finishreview 
    params[:opinion][:user_id]=session[:user_id]    
    params[:opinion][:enterprise_id]=session[:enterprise_id]
    session[:enterprise_id]=nil
    #set default
    params[:opinion][:taste_grade_id]=params[:opinion][:taste_grade_id]? 1:params[:opinion][:taste_grade_id]
    params[:opinion][:entironment_grade_id]=params[:opinion][:entironment_grade_id]? 1:params[:opinion][:entironment_grade_id]
    params[:opinion][:service_grade_id]=params[:opinion][:service_grade_id]? 1:params[:opinion][:service_grade_id]
    params[:opinion][:general_grade_id]=params[:opinion][:general_grade_id]? 1:params[:opinion][:general_grade_id]
    
    @opinion=Opinion.new(params[:opinion])
    
    #    respond_to do |format|
    #      format.html {render :template=> "/review/startreview"}
    #    end
    respond_to do |format|
      if (@opinion.save)    
        flash[:notice] = '点评成功.'
        format.html {  redirect_to(:controller=>"home", :action=>"main", :id=> session[:user_id]) }
      else
        format.html { render :action => "startreview" }
        format.xml  { render :xml => @opinion.errors, :status => :unprocessable_entity }
      end
    end
  end
end